package com.baizhi.controller;

import com.baizhi.entity.Book;
import com.baizhi.service.BookService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("book")
public class BookController {
    private BookService bookService;
    @Autowired
    public void setBookService(BookService bookService) {
        this.bookService = bookService;
    }
    @RequestMapping("selectBooks")
    @ResponseBody
    public Map selectBooks(Integer page,Integer limit){
        PageInfo<Book> pageInfo = bookService.selectBook(page, limit);
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",pageInfo.getTotal());
        map.put("data",pageInfo.getList());
        return map;
    }
    @RequestMapping("addBook")
    public String addBook(Book b){
        System.out.println("book="+b);
        bookService.addBook(b);
        return "redirect:selectBooks";
    }
}
